﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

/// <summary>
/// 操作系统(从指令中指定技能朝向，移动朝向和速度)
/// </summary>
public class OperationSystem : ECSSystemtBase
{
    public override Type[] GetFilter()
    {
        return new Type[]
        {
            typeof(CommandComponent),
            typeof(MoveComponent),
            typeof(PlayerCom),
            typeof(LifeCom),
            typeof(BlowFlyComponent),
        };
    }

    public override void BeforeFixedUpdate(int delaTime)
    {
        List<ECSEntityBase> list = GetEntityList();
        if (list.Count==0)
        {
            return;
        }
        ECSEntityBase ecs;
        for (int i = 0,j=list.Count; i < j; i++)
        {
            ecs = list[i];
            CommandComponent com = ecs.GetCom<CommandComponent>();
            MoveComponent move = ecs.GetCom<MoveComponent>();
            PlayerCom plc = ecs.GetCom<PlayerCom>();
            LifeCom lc = ecs.GetCom<LifeCom>();
            BlowFlyComponent bfc = ecs.GetCom<BlowFlyComponent>();
            //存活，非蝇，非晕眩
            if (lc.life>0&&!bfc.isBlow&&!plc.GetISDizziness())
            {
                plc.facDir = com.skillDir.DeepCopy();//拿到技能朝向
                move.dir = com.moveDir.DeepCopy();//拿到移动方向

                move.m_velocity = plc.GetSpeed();//拿到移速
            }
            else
            {
                 move.dir.FromVector3(Vector3.zero);
            }
        }
    }
}

